﻿/***************************************************************************
//* Foxit Software Inc.
//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc.                                                      *
***************************************************************************/

/**
* PDF 文档数据
*/

define(function (require, exports, module) {
    require('../DataLevel.js');
    require('./PDFPage.js');
    require('./PDFDocProperties.js');
	 /**
     * @name FXREADER.PDFData.DocType
     * @namespace  
	 * @description enumeration of PDF docuemnt type.
     */
    FXREADER.PDFData.DocType = {
		 /**
        * @description Normal PDF.
        * @type {Number}
        * @constant
        */
        PDF: 1,
		 /**
        * @description Acroform PDF.
        * @type {Number}
        * @constant
        */
        FORM: 2,
		 /**
        * @description XFA PDF.
        * @type {Number}
        * @constant
        */
        XFA: 3
    };

	/**
    * PDF Document.
    * @class PDF Document. 
    * @constructor
    * @param {FXREADER.PDFData.DocType} docType 	 document type
    * @return a PDF document object
    */
    FXREADER.PDFData.CPDF_Document = function (docType) {

        var _DocType = docType,                       //文档类型
             _DocProperties = null,
             _StartShowPage = 0,      //限制可以显示的开始页
             _EndShowPage = -1, //限制可以显示的页的个数，0为全部显示
             _PDFPages = [],                //页面
        
        	 _PDFPageInfo = [], //页面级数据
        	 _PDFFontInfo = []; //字体对象
        	 

        /**
        * @description Get the type of PDF Document.
        * @return {FXREADER.PDFData.DocType} the type of PDF Document. 
        */     
        this.GetDocType = function () {
            return _DocType;
        };

		/**
        * @description Set the type of PDF Document.
        * @param {FXREADER.PDFData.DocType} docType PDF Document type. 
        */  
        this.SetDocType = function (docType) {
            _DocType = docType;
        };

        //获取和设置文档信息
        this.SetDocProperties = function (docProperties) {
            _DocProperties = docProperties;
        };
        this.GetDocProperties = function () {
            return _DocProperties;
        };

        /**
        * @description Get a PDF page object by index.
		* @param {Number} page_index   the page index.
        * @return {FXREADER.PDFData.CPDF_Page} a PDF page object by index.
        */ 
        this.GetPage = function (page_index) {
            if (isNaN(page_index))
                return null;
            return _PDFPages[page_index];
        };
        /**
        * @description Get the page count of the PDF document.
        * @return {Number} The page count of the PDF document.
        */
        this.GetPageCount = function () {
            return _PDFPages.length;
        };

        this.AddPage = function (pPDFPage) {
            _PDFPages.push(pPDFPage);
        };

        this.DeletePage = function (pageIndex) {
            if (isNaN(pageIndex) || pageIndex > _PDFPages.length || pageIndex < 0) { return false; }
            delete _PDFPages[pageIndex];
            _PDFPages.splice(pageIndex, 1);
            return true;
        };

        /**
        * @description Check whether the page can be display.
		* @param {Number} page_index the page index
        * @return {Boolean} return true if the page can be dispaly, otherwise return false.
        */
        this.IsCanShowPage = function (pageIndex) {
            if (isNaN(pageIndex) || pageIndex > _PDFPages.length || pageIndex < 0) { return false; }
            if (_EndShowPage == -1 || _EndShowPage < _StartShowPage) return true;
            if (pageIndex < _StartShowPage || pageIndex > _EndShowPage) return false;
            return true;
        };
        this.SetShowPageRange = function (nStartShowPage, nEndShowPage) { _StartShowPage = nStartShowPage; _EndShowPage = nEndShowPage; };
    };

    return FXREADER.PDFData.CPDF_Document;
});